package com.haixee.parkdemo.auth.controller;

import com.haixee.parkdemo.auth.model.DataScope;
import com.haixee.parkdemo.auth.model.FieldRule;
import com.haixee.parkdemo.auth.service.DataAccessService;
import com.haixee.parkdemo.common.response.ResResult;
import com.haixee.parkdemo.common.response.ResUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/data_acl")
public class DataAclController {

    @Autowired
    private DataAccessService dataAccessService;

    @GetMapping("/scope")
    public ResResult scope(Integer modelId) {
        return ResUtil.success(dataAccessService.getByModuleId(modelId));
    }

    @PostMapping("/scope")
    public ResResult updateScope(@RequestBody DataScope dataScope) {
        dataAccessService.updateScore(dataScope);
        return ResUtil.success();
    }

    @GetMapping("/rule")
    public ResResult rule(Integer aclId) {
        return ResUtil.success(dataAccessService.getFieldRules(aclId, null));
    }

    @GetMapping("/rule/show")
    public ResResult ruleShow(Integer aclId) {
        return ResUtil.success(dataAccessService.getFieldRuleShow(aclId));
    }

    @PostMapping("/rule/add")
    public ResResult addRule(@RequestBody FieldRule rule) {
        dataAccessService.addFieldRule(rule);
        return ResUtil.success();
    }

    @PostMapping("/rule/update")
    public ResResult updateRule(@RequestBody FieldRule rule) {
        dataAccessService.updateFieldRule(rule);
        return ResUtil.success();
    }
}
